package jdbc;

import java.sql.*;

public class JDBCQuick {
    public static void main(String[] args) throws Exception {
        //1.注册驱动


        //2.获取数据库连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/atguigu?useSSL=false","root","8867993");

        //3.编写SQL语句，创建Statement
        String sql = "select emp_id,emp_name,emp_salary,emp_age from t_emp;";
        PreparedStatement statement = connection.prepareStatement(sql);


        //4.获取执行结果
        ResultSet resultSet = statement.executeQuery();

        //5.处理结果
        while (resultSet.next()){
            int empId = resultSet.getInt("emp_id");
            String empName = resultSet.getString("emp_name");
            String empSalary = resultSet.getString("emp_salary");
            int empAge = resultSet.getInt("emp_age");
            System.out.println(empId + "\t" + empName + "\t" + empSalary + "\t" + empAge);
        }

        //6.释放资源
        resultSet.close();
        statement.close();
        connection.close();

    }
}
